home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 18 / CU Amiga Magazine's Super CD-ROM 18 (1997)(EMAP Images)(GB)[!][issue 1998-01].iso / CUCD / Programming / AmigaE / Src / Tools / FilledVector / examples / cube.e next >
Encoding:
Text File  |  1994-07-06  |  1.7 KB  |  70 lines

  1.  
  2. /*
  3.  
  4.   A _simple_ cube example, using Workbench 1.3 code
  5.  
  6.   FilledVector.m module example code, Michael Zucchi
  7.  
  8.   This code in the public domain
  9.  
  10. */
  11.  
  12. OPT OSVERSION=33
  13.  
  14. MODULE 'intuition/intuition', 'intuition/screens',
  15.     'tools/filledvector', 'tools/filledvdefs'
  16.  
  17. DEF s0:PTR TO screen, s1:PTR TO screen, scr:PTR TO screen,
  18.     pc,cube:PTR TO vobject, destz=2000;
  19.  
  20. PROC main()
  21.  
  22. s0:=OpenS(320,200,4,0,'3d Cube');    -> 2 screens for doublebuffering
  23. s1:=OpenS(320,200,4,0,'3d Cube');
  24.  
  25. pc:=newPolyContext(s0.bitmap,20)    -> create context
  26. setPolyFlags(pc,1,1)            -> turn on zclipping
  27.  
  28.  cube:=newVectorObject(0,    -> basic type
  29.      8,            -> 8 points
  30.      6,            -> 6 faces
  31.     [-100,100,-100,    -> 0    -> points array
  32.     100,100,-100,    -> 1
  33.     100,-100,-100,    -> 2
  34.     -100,-100,-100,    -> 3
  35.     -100,100,100,    -> 4
  36.     100,100,100,    -> 5
  37.     100,-100,100,    -> 6
  38.     -100,-100,100]:INT,    -> 7    -> faces array below
  39.     [0,1,2, 1, [4, 0,1,1,2,2,3,3,0]:INT, 0,    -> front
  40.     6,5,4, 2, [4, 4,5,5,6,6,7,7,4]:INT, 0,    -> back
  41.     2,1,5, 3, [4, 1,5,5,6,6,2,2,1]:INT, 0,    -> right
  42.     4,0,3, 4, [4, 4,0,0,3,3,7,7,4]:INT, 0,    -> left
  43.     1,0,4, 5, [4, 0,1,1,5,5,4,4,0]:INT, 0,    -> top
  44.     7,3,2, 6, [4, 3,2,2,6,6,7,7,3]:INT, 0]:face);    -> bottom
  45.  
  46. scr:=s0
  47. cube.pz:=1000;
  48.  
  49. WHILE Mouse()<>3
  50.   SetRast(scr.rastport,0);        -> clear the screen
  51.   setPolyBitMap(pc, scr.bitmap);    -> take note of change
  52.   drawVObject(pc, cube);        -> draw to off-screen
  53.  
  54.   ScreenToFront(scr);            -> bring it to the front
  55.  
  56.   cube.ax:=cube.ax+1            -> move object
  57.   cube.ay:=cube.ay+2
  58.   cube.az:=cube.az+3
  59.   cube.pz:=cube.pz+((destz-cube.pz)/6)
  60.   IF Abs(cube.pz-destz)<6 THEN destz:=Rnd(2000)+10
  61.  
  62.   IF scr=s0 THEN scr:=s1 ELSE scr:=s0;    -> swap screens
  63. ENDWHILE
  64.  
  65. freeVectorObject(cube);
  66. CloseS(s0)
  67. CloseS(s1)
  68.  
  69. ENDPROC
  70.